package com.rc.saas.tenant.service.hlht;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.base.BaseSearch;
import com.rc.saas.tenant.mapper.hlht.HlhtOperatorMapper;
import com.rc.saas.tenant.model.hlht.HlhtOperator;
import com.rc.saas.tenant.model.hlht.HlhtOperatorExample;
import com.rc.saas.tenant.vo.hlht.HlhtTenantVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author frog
 * @date 2021/4/16
 */
@Service
public class HlhtOperatorServiceImpl implements HlhtOperatorService {

    @Autowired
    private HlhtOperatorMapper hlhtOperatorMapper;

    @Override
    public HlhtOperatorMapper getMapper() {
        return hlhtOperatorMapper;
    }

    @Override
    public PageInfo<HlhtOperator> listPageHlhtOperator(BaseSearch baseSearch) {
        PageHelper.startPage(baseSearch.getOffset(), baseSearch.getLimit());
        HlhtOperatorExample example = new HlhtOperatorExample();
        List<HlhtOperator> hlhtOperators = hlhtOperatorMapper.selectByExample(example);
        return new PageInfo<HlhtOperator>(hlhtOperators);
    }

    @Override
    public List<HlhtTenantVo> listAllHlhtTenantVo() {

        List<HlhtTenantVo> list = new ArrayList<>();

        HlhtOperatorExample example = new HlhtOperatorExample();
        example.createCriteria().andOperatorTypeEqualTo("0").andStatusEqualTo("0");

        List<HlhtOperator> hlhtOperators = hlhtOperatorMapper.selectByExample(example);
        for (HlhtOperator hlhtOperator : hlhtOperators) {
            HlhtTenantVo hlhtTenantVo = new HlhtTenantVo();
            hlhtTenantVo.setCode(hlhtOperator.getHlhtOperatorId());
            hlhtTenantVo.setName(hlhtOperator.getHlhtOperatorName() + "(" + hlhtOperator.getHlhtOperatorShortname() + ")");
            list.add(hlhtTenantVo);
        }

        return list;
    }

    @Override
    public List<HlhtTenantVo> listAllHlhtTenantVo(String tenantCode) {

        List<HlhtTenantVo> list = new ArrayList<>();
        List<HlhtOperator> hlhtOperators = hlhtOperatorMapper.listHlhtOperatorByTenantCode(tenantCode);

        for (HlhtOperator hlhtOperator : hlhtOperators) {
            HlhtTenantVo hlhtTenantVo = new HlhtTenantVo();
            hlhtTenantVo.setCode(hlhtOperator.getHlhtOperatorId());
            hlhtTenantVo.setName(hlhtOperator.getHlhtOperatorName() + "(" + hlhtOperator.getHlhtOperatorShortname() + ")");
            list.add(hlhtTenantVo);
        }
        return list;
    }
}
